<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>达内－NetCTOSS</title>
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css" />
        <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css" />
        <script language="javascript" type="text/javascript" src="../js/jquery-1.4.3.js"></script>
        <script language="javascript" type="text/javascript">
        	rName=false,rLogin=false,rPassS=false,rPassF=false,rPhone=false,theEmail=false;
            //保存成功的提示消息
            function showResult() {
            	if(rName==true&&rLogin==true&&rPassS==true&&rPassF==true&&rPhone==true&&theEmail==true){
            		var flag1 = 0;
		            var checkobj=document.getElementById("CheckBoxList");
		            var checks = checkobj.getElementsByTagName("input");
		            for(var n = 0; n<checks.length;n++){
		            	if( checks[n].checked==true){
		            		flag1=1;
		            	}
		            }
		            if(flag1==0){
		            	$("#save_result_info").text("请至少选择一项权限");
		                showResultDiv(true);
		                window.setTimeout("showResultDiv(false);", 1000);
		            	return;
		            }
                	showResultDiv(true);
                	document.forms[0].submit();
                	window.setTimeout("showResultDiv(false);", 1000);
            	}
            }
            function showResultDiv(flag) {
                var divResult = document.getElementById("save_result_info");
                if (flag)
                    divResult.style.display = "block";
                else
                    divResult.style.display = "none";
            }
            $(function(){
            	//姓名
            	$("#realName").blur(function(){
            		var name = $(this).val();
            		var reg = /^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$/;
            		if(!reg.test(name)){
            			$("#realNameMsg").addClass("error_msg").text("请输入正确的姓名");
            			rName=false;
            			return;
            		}else{
            			$("#realNameMsg").removeClass("error_msg").text("输入正确");
            			rName=true;
            		}
            	});
            	//管理员账号
            	$("#adminCode").blur(function(){
            		var adminCode = $(this).val();
            		var reg = /^[\w]{1,20}$/;
            		if(!reg.test(adminCode)){
            			$("#adminCodeMsg").addClass("error_msg").text("请输入正确的账号");
            			rLogin=false;
            			return;
            		}else{
	            		$.post(
	            			"checkAdmin",{"adminCode":adminCode},function(data){
	            				var account = data;
	            				if(account == null){
				            		$("#adminCodeMsg").removeClass("error_msg").text("输入正确");
				            		rLogin=true;
	            				}else{
		            				$("#adminCodeMsg").addClass("error_msg").text("该登录名已经存在");
		            				rLogin=false;
	            				}
            				}
            			);
            		}
            	});
            	//密码
            	$("#passWd").blur(function(){
            		var passWord = $(this).val();
            		var reg = /^[\w]{1,20}$/;
            		if(!reg.test(passWord)){
            			$("#passWdMsg").addClass("error_msg").text("请输入正确的密码");
            			rPassF=false;
            			return;
            		}else{
            			$("#passWdMsg").removeClass("error_msg").text("输入正确");
            			rPassF=true;
            		}
            		if(passWord != $("#rePassWd").val()){
            			$("#rePassWdMsg").addClass("error_msg").text("请输入与上面相同的密码");
            			rPassS=false;
            		}else if(passWord == $("#rePassWd").val()){
            			$("#rePassWdMsg").removeClass("error_msg").text("输入正确");
            			rPassS=true;
            		}
            	});
            	//重复密码
            	$("#rePassWd").blur(function(){
            		var passW = $("#passWd").val();
            		var rePassW = $(this).val();
            		if(passW != rePassW){
            			$("#rePassWdMsg").addClass("error_msg").text("您输入的密码与上面不同");
            			rPassS=false;
            			return;
            		}else{
            			if(rePassW!=null&&rePassW!=""){
	            			$("#rePassWdMsg").removeClass("error_msg").text("输入正确");
	            			rPassS=true;
            			}else{
            				$("#rePassWdMsg").addClass("error_msg").text("请输入密码");
            				rPassS=false;
            			}
            		}
            	});
            	//电话
           		$("#thePhone").blur(function(){
            		var phone = $(this).val();
            		var tel = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
            		var pho = /\d{3}-\d{8}|\d{4}-\d{7}/;
            		if(!tel.test(phone)&&!pho.test(phone)){
            			$("#thePhoneMsg").addClass("error_msg").text("请输入正确的号码");
            			rPhone=false;
            			return;
            		}else{
            			$("#thePhoneMsg").removeClass("error_msg").text("输入正确");
            			rPhone=true;
            		}
            	});
            	//Email
            	$("#theEmail").blur(function(){
            		var email = $(this).val();
            		var len = email.length;
            		var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
            		if(!reg.test(email)||len>50){
            			$("#theEmailMsg").addClass("error_msg").text("请输入正确的Email地址");
            			theEmail = false;
            			return;
            		}else{
            			theEmail = true;
            			$("#theEmailMsg").removeClass("error_msg").text("输入正确");
            		}
            	});
            });
        </script>
    </head>
    <body>
        <!--Logo区域开始-->
        <div id="header">
            <img src="../images/logo.png" alt="logo" class="left"/>
            <a href="#">[退出]</a>            
        </div>
        <!--Logo区域结束-->
        <!--导航区域开始-->
        <div id="navi">
            <ul id="menu">
                <li><a href="../index/index" class="index_off"></a></li>
                <li><a href="../role/findRole" class="role_off"></a></li>
                <li><a href="../admin/findAdmin" class="admin_on"></a></li>
                <li><a href="../cost/findCost" class="fee_off"></a></li>
                <li><a href="../account/findAccount" class="account_off"></a></li>
                <li><a href="../service/findService" class="service_off"></a></li>
                <li><a href="../bill/findBill" class="bill_off"></a></li>
                <li><a href="../report/findReport" class="report_off"></a></li>
                <li><a href="../user/userInfo" class="information_off"></a></li>
                <li><a href="../user/userModiPwd" class="password_off"></a></li>
            </ul>
        </div>
        <!--导航区域结束-->
        <!--主要区域开始-->
        <div id="main">            
            <div id="save_result_info" class="save_success">保存成功！</div>
            <form action="addAdmin" method="get" class="main_form">
                    <div class="text_info clearfix"><span>姓名：</span></div>
                    <div class="input_info">
                        <input type="text" id="realName" name="admin.name"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="realNameMsg">20长度以内的汉字、字母、数字的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>管理员账号：</span></div>
                    <div class="input_info">
                        <input type="text" id="adminCode" name="admin.adminCode"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="adminCodeMsg">30长度以内的字母、数字和下划线的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>密码：</span></div>
                    <div class="input_info">
                        <input type="password" id="passWd" name="admin.password"/>
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="passWdMsg">30长度以内的字母、数字和下划线的组合</div>
                    </div>
                    <div class="text_info clearfix"><span>重复密码：</span></div>
                    <div class="input_info">
                        <input type="password" id="rePassWd" />
                        <span class="required">*</span>
                        <div class="validate_msg_long" id="rePassWdMsg">两次密码必须相同</div>
                    </div>      
                    <div class="text_info clearfix"><span>电话：</span></div>
                    <div class="input_info">
                        <input type="text" class="width200" id="thePhone" name="admin.telephone"/>
                        <span class="required">*</span>
                        <div class="validate_msg_medium" id="thePhoneMsg">正确的电话号码格式：手机或固话</div>
                    </div>
                    <div class="text_info clearfix"><span>Email：</span></div>
                    <div class="input_info">
                        <input type="text" class="width200" id="theEmail" name="admin.email"/>
                        <span class="required">*</span>
                        <div class="validate_msg_medium" id="theEmail">50长度以内，正确的 email 格式</div>
                    </div>
                    <div class="text_info clearfix"><span>角色：</span></div>
                    <div class="input_info_high">
                        <div class="input_info_scroll" id="CheckBoxList">
                        	<s:checkboxlist list="roles" name="admin.roleIds" listKey="id" listValue="name"></s:checkboxlist>
                        </div>
                        <span class="required">*</span>
                        <div class="validate_msg_tiny">至少选择一个</div>
                    </div>
                    <div class="button_info clearfix">
                        <input type="button" value="保存" class="btn_save" onclick="showResult();" />
                        <input type="button" value="取消" class="btn_save" onclick="javascript:history.go(-1);"/>
                    </div>
                </form>  
        </div>
        <!--主要区域结束-->
        <div id="footer">
            <span>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</span>
            <br />
            <span>版权所有(C)加拿大达内IT培训集团公司 </span>
        </div>
    </body>
</html>

